package com.qfedu.utils;

import static java.lang.Math.*;

/**
 * 千锋Java,为你而生！
 *
 * @Author: Feri
 * @Date:2024/11/21 17:06
 * @Modified:
 */
public class DistanceUtil {
    private static final double EARTH_RADIUS = 6371000; // 地球半径，单位米
    public static Double getDistance(double lat1, double lon1, double lat2, double lon2){
        double latDistance = toRadians(lat2 - lat1);
            double lonDistance = toRadians(lon2 - lon2);
            double a = sin(latDistance / 2) * sin(latDistance / 2) +
                    cos(toRadians(lat1)) * cos(toRadians(lat2)) *
                            sin(lonDistance / 2) * sin(lonDistance / 2);
            double c = 2 * atan2(sqrt(a), sqrt(1 - a));
            return EARTH_RADIUS * c;

    }
}
